// TabBar 配置
export const tabBarConfig = {
  color: '#999999',
  selectedColor: '#FF69B4',
  backgroundColor: '#FFFFFF',
  borderStyle: 'black',
  list: [
    {
      pagePath: '/pages/index/index',
      text: '首页',
      iconPath: '/static/home.svg',
      selectedIconPath: '/static/home-active.svg',
      name: 'Home'
    },
    {
      pagePath: '/pages/tabs/project/index',
      text: '项目',
      iconPath: '/static/folder.svg',
      selectedIconPath: '/static/folder-active.svg',
      name: 'Project'
    },
    {
      pagePath: '/pages/tabs/profile/index',
      text: '我的',
      iconPath: '/static/user.svg',
      selectedIconPath: '/static/user-active.svg',
      name: 'Profile'
    }
  ]
}

// 使用uni-app内置路由API的路由工具
export const tabBarUtils = {
  // 获取当前tab索引
  getCurrentTabIndex(path) {
    return tabBarConfig.list.findIndex(item => item.pagePath === path)
  },
  
  // 使用uni-app内置API跳转到指定tab
  switchToTab(pagePath) {
    uni.switchTab({
      url: pagePath
    })
  },
  
  // 获取tab配置
  getTabConfig(pagePath) {
    return tabBarConfig.list.find(item => item.pagePath === pagePath)
  },
  
  // 带参数的路由跳转
  navigateTo(url, params = {}) {
    const queryString = Object.keys(params).map(key => `${key}=${params[key]}`).join('&')
    const fullUrl = queryString ? `${url}?${queryString}` : url
    uni.navigateTo({
      url: fullUrl
    })
  },
  
  // 返回上一页
  goBack(delta = 1) {
    uni.navigateBack({
      delta
    })
  },
  
  // 替换当前页面
  replaceTo(url, params = {}) {
    const queryString = Object.keys(params).map(key => `${key}=${params[key]}`).join('&')
    const fullUrl = queryString ? `${url}?${queryString}` : url
    uni.redirectTo({
      url: fullUrl
    })
  }
}